package com.bit.review;

/**
 * 克隆
 * 空接口：标记接口：  表示当前类  是能被克隆的
 * 深拷贝
 */

class Money implements Cloneable{

    public double money = 19.99;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

class Person implements Cloneable{

    public int age = 19;
    public Money m = new Money();

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person tmp = (Person) super.clone();
        //return super.clone();
        tmp.m = (Money) this.m.clone();
        return tmp;
    }
}


public class TestDemo2 {

   /* public static void main(String[] args) throws CloneNotSupportedException {
        Person person2 = new Person();
        Person Person2 = (Person) person2.clone();
    }*/

    public static void main(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person();
        Person person2 = (Person) person1.clone();
/**
 * 深拷贝
 * 想通过  person2.m.money修改之后不会影响原来的数据
 */
        System.out.println(person1.m.money);
        System.out.println(person2.m.money);
        person2.m.money = 899.99;
        System.out.println("=====================");
        System.out.println(person1.m.money);
        System.out.println(person2.m.money);
       /* System.out.println(person1.age);
        System.out.println(person2.age);
        person2.age = 899;
        System.out.println("=====================");
        System.out.println(person1.age);
        System.out.println(person2.age);*/
    }
}
